<?php
class Mweibo extends CI_Model{
	function __construct(){
		parent::__construct();
	}
	function saveWeibo($uid,$wid,$url){
		$this->delWeibo($wid, $uid);
		$sql = "insert into tbweibo(uid,url,wid,status) values(?,?,?,1)";
		$this->db->query($sql,array("$uid","$url","$wid"));
		return $this->db->affected_rows();
	}
	function delWeibo($wid,$uid){
		$sql = "delete from tbweibo 
				where wid = ? and uid = ?";
		$this->db->query($sql,array("$wid","$uid"));
	}
	function loadWeibo($uid){
		$sql = "select *
				from tbweibo
				where uid = ?";
		$query = $this->db->query($sql,array("$uid"));
		return $query->result();
	}

    function checkWeibo($uid){
        $sql = "select *
				from tbweibo
				where uid = ?";
        $query = $this->db->query($sql,array("$uid"));
        $exists = false;
        foreach ($query->result() as $row){
            return true;
        }
        return $exists;
    }

    /**
     * 根据某一类别的微薄账号
     * @param $uid
     * @param $wid
     * @return mixed
     */
    function getWeiBoByUid($uid,$wid){
        $sql = "select *
				from tbweibo
				where wid = ? and uid = ?";
        $query = $this->db->query($sql,array($wid,$uid));
        return $query->row_array();
    }
}

?>